package com.ruoyi.business.controller;

import com.ruoyi.business.service.IWsdCanteenStaffService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.WsdCanteenStaff;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 饭堂人员管理Controller
 * 
 * @author ruoyi
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/wsd_canteen_staff")
public class WsdCanteenStaffController extends BaseController {

    @Autowired
    private IWsdCanteenStaffService wsdCanteenStaffService;


    /**
     * 查询饭堂人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(WsdCanteenStaff wsdCanteenStaff) {
        //获取学校id
        SysUser user = getLoginUser().getUser();
        Long schoolId = user.getSchoolId();
        wsdCanteenStaff.setSchoolId(schoolId);
        startPage();
        List<WsdCanteenStaff> list = wsdCanteenStaffService.selectWsdCanteenStaffList(wsdCanteenStaff);
        return getDataTable(list);
    }

    /**
     * 导出饭堂人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:staff:export')")
    @Log(title = "饭堂人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WsdCanteenStaff wsdCanteenStaff)
    {
        List<WsdCanteenStaff> list = wsdCanteenStaffService.selectWsdCanteenStaffList(wsdCanteenStaff);
        ExcelUtil<WsdCanteenStaff> util = new ExcelUtil<WsdCanteenStaff>(WsdCanteenStaff.class);
        util.exportExcel(response, list, "饭堂人员管理数据");
    }

    /**
     * 获取饭堂人员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:staff:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wsdCanteenStaffService.selectWsdCanteenStaffById(id));
    }

    /**
     * 新增饭堂人员管理
     */
    @PreAuthorize("@ss.hasPermi('business:staff:add')")
    @Log(title = "饭堂人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WsdCanteenStaff wsdCanteenStaff)
    {
        //获取学校id
        SysUser user = getLoginUser().getUser();
        Long schoolId = user.getSchoolId();
        wsdCanteenStaff.setSchoolId(schoolId);
        return toAjax(wsdCanteenStaffService.insertWsdCanteenStaff(wsdCanteenStaff));
    }

    /**
     * 修改饭堂人员管理
     */
    @PreAuthorize("@ss.hasPermi('business:staff:edit')")
    @Log(title = "饭堂人员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WsdCanteenStaff wsdCanteenStaff)
    {
        return toAjax(wsdCanteenStaffService.updateWsdCanteenStaff(wsdCanteenStaff));
    }

    /**
     * 删除饭堂人员管理
     */
    @PreAuthorize("@ss.hasPermi('business:staff:remove')")
    @Log(title = "饭堂人员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wsdCanteenStaffService.deleteWsdCanteenStaffByIds(ids));
    }
}
